package com.chenfubing.ps.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfubing.ps.entity.Car;
import com.chenfubing.ps.entity.result.JsonResult;
import com.chenfubing.ps.service.ICarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chenfubing
 * @since 2020-05-05
 */
@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    private ICarService iCarService;

    /**
     * 添加车辆
     *
     * @param car
     */
    @PostMapping("/addCar")
    public JsonResult addCar(@Validated @RequestBody Car car) {
        iCarService.addCar(car);
        return new JsonResult();
    }

    /**
     * 删除车辆
     *
     * @param license
     */
    @GetMapping("/deleteCar")
    public JsonResult deleteCar(@RequestParam String license) {
        iCarService.deleteCar(license);
        return new JsonResult();
    }

    /**
     * 根据车牌号查询车辆
     *
     * @param license
     * @return
     */
    @GetMapping("/findCar")
    public JsonResult findCar(@RequestParam String license) {
        return new JsonResult(iCarService.findCar(license)) ;
    }

    /**
     * 分页
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getCarPage")
    public JsonResult getCarPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
        return new JsonResult(iCarService.getCarPage(pageNum, pageSize)) ;
    }

    @GetMapping("/export")
    public JsonResult export()
    {
        iCarService.export();
        return new JsonResult();
    }
}
